package com.yzmoney.wechat.action;

import com.yzmoney.common.constant.Constants;
import com.yzmoney.common.model.JsonResult;
import com.yzmoney.wechat.service.WechatAccessTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller()
@RequestMapping(value = "/wechat")
public class AccessTokenAction {
    @Autowired
    private WechatAccessTokenService wechatAccessTokenService;

    @RequestMapping(value = "getGZHAccessToken")
    @ResponseBody
    public JsonResult getGZHAccessToken() {
        JsonResult result = new JsonResult();
        try {
            result.setData(wechatAccessTokenService.getGZHAccessToken());
        }catch (Exception e){
            result.setCode(Constants.CODE_FAILURE);
        }
        return result;
    }

    @RequestMapping(value = "refreshGZHAccessToken")
    @ResponseBody
    public JsonResult refreshGZHAccessToken(){
        JsonResult result = new JsonResult();
        result.setData(wechatAccessTokenService.refreshGZHAccessToken());
        return result;
    }

    @RequestMapping(value = "getQYHAccessToken")
    @ResponseBody
    public JsonResult getQYHAccessToken() {
        JsonResult result = new JsonResult();
        try {
            result.setData(wechatAccessTokenService.getQYHAccessToken());
        }catch (Exception e){
            result.setCode(Constants.CODE_FAILURE);
        }
        return result;
    }

    @RequestMapping(value = "refreshQYHAccessToken")
    @ResponseBody
    public JsonResult refreshQYHAccessToken(){
        JsonResult result = new JsonResult();
        result.setData(wechatAccessTokenService.refreshQYHAccessToken());
        return result;
    }
}
